package com.zmn.plat.admin.controller.supplier;

import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;

import javax.annotation.Resource;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.zmn.common.constant.GlobalConsts;
import com.zmn.common.dto.VtDTO;
import com.zmn.plat.admin.controller.PlatBaseController;
import com.zmn.plat.business.interfaces.supplier.ScmSupplierBService;
import com.zmn.plat.common.constant.CompanyConsts;
import com.zmn.plat.model.entity.company.BaseCompany;
import com.zmn.plat.model.entity.company.BaseCompanyQuery;
import com.zmn.plat.services.interfaces.company.BaseCompanyService;
import com.zmn.plat.services.interfaces.supplier.ScmSupplierCompanyMapService;
import com.zmn.plat.services.interfaces.supplier.ScmSupplierService;

/**
 * @author DaiZhichao
 * @version v1.0
 * @since 2018/10/26 20:21 类说明：ScmSupplierBaseController
 */

public class ScmSupplierBaseController extends PlatBaseController {

    private Logger logger = LoggerFactory.getLogger(this.getClass());

    @Resource
    ScmSupplierService scmSupplierService;
    @Resource
    ScmSupplierBService scmSupplierBService;
    @Resource
    ScmSupplierCompanyMapService supplierCompanyMapService;

    @Resource
    BaseCompanyService companyService;

    /**
     * 描述:调用【公司】服务，返回【公司】列表
     *
     * @return List<VtDTO>
     * @author DaiZhichao
     * @since 2018/11/7 15:13
     */
    public List<BaseCompany> getCompanyList(BaseCompanyQuery companyQuery) {
        return companyService.listByQuery(companyQuery);
    }

    /**
     * 描述:调用【公司】服务，返回【供应商公司】简单列表
     *
     * @return List<VtDTO>
     * @author DaiZhichao
     * @since 2018/11/7 15:13
     */
    public List<VtDTO> getSupplierCompanySimpleList() {
        return getCompanyList(BaseCompanyQuery.builder().type(CompanyConsts.COMPANY_TYPE_SUPPLIER)
            .childType(CompanyConsts.COMPANY_TYPE_CHILD_DEFAULT).build()).stream()
                .map(company -> new VtDTO(company.getCompanyId(), company.getFullName(), company.getStatus())).collect(Collectors.toList());
    }

    /**
     * 描述:调用【公司】服务，返回【平台公司】简单列表
     *
     * @return List<VtDTO>
     * @author DaiZhichao
     * @since 2018/11/7 15:13
     */
    public List<VtDTO> getPlatformCompanySimpleList() {
        List<VtDTO> companyList = getCompanyList(BaseCompanyQuery.builder().type(CompanyConsts.COMPANY_TYPE_SUBSIDIARY)
            .childType(CompanyConsts.COMPANY_TYPE_CHILD_DEFAULT).build()).stream()
                .map(company -> new VtDTO(company.getCompanyId(), company.getName(), company.getStatus())).collect(Collectors.toList());
        List<VtDTO> companyListAll = new ArrayList<>();
        companyListAll.add(new VtDTO(GlobalConsts.ZMN_COMPANY_ID, "啄木鸟"));
        companyListAll.add(new VtDTO(GlobalConsts.YEYX_COMPANY_ID, "言而有信"));
        companyListAll.add(new VtDTO(GlobalConsts.YBSH_COMPANY_ID, "一步生活"));
        companyListAll.add(new VtDTO(GlobalConsts.CNHB_COMPANY_ID, "川南环保"));
        companyListAll.addAll(companyList);
        return companyListAll;
    }

    public boolean isZmnCompany() {
        return isZmnCompany(getMcStaff().getCompanyId());
    }

    public boolean isZmnCompany(Integer companyId) {
        Integer zmnCompanyId = companyService.findZmnCompanyId();
        logger.info("传入的公司ID:" + companyId);
        logger.info("总公司ID:" + zmnCompanyId);
        logger.info("传入的公司是总公司?:" + Objects.equals(companyId, zmnCompanyId));
        return Objects.equals(companyId, zmnCompanyId);
    }

}
